package com.lifeservice.console.controller;

import com.lifeservice.common.annotation.Log;
import com.lifeservice.common.core.controller.BaseController;
import com.lifeservice.common.core.domain.AjaxResult;
import com.lifeservice.common.core.page.TableDataInfo;
import com.lifeservice.common.enums.BusinessType;
import com.lifeservice.common.utils.poi.ExcelUtil;
import com.lifeservice.console.domain.LifeCityBuilding;
import com.lifeservice.console.service.ILifeCityBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市大厦信息Controller
 *
 * @author lifeservice
 * @date 2023-03-01
 */
@RestController
@RequestMapping("/console/building")
public class LifeCityBuildingController extends BaseController {
    @Autowired
    private ILifeCityBuildingService lifeCityBuildingService;

    /**
     * 查询城市大厦信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LifeCityBuilding lifeCityBuilding) {
        startPage();
        List<LifeCityBuilding> list = lifeCityBuildingService.selectLifeCityBuildingList(lifeCityBuilding);
        return getDataTable(list);
    }

    /**
     * 导出城市大厦信息列表
     */
    @Log(title = "城市大厦信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeCityBuilding lifeCityBuilding) {
        List<LifeCityBuilding> list = lifeCityBuildingService.selectLifeCityBuildingList(lifeCityBuilding);
        ExcelUtil<LifeCityBuilding> util = new ExcelUtil<LifeCityBuilding>(LifeCityBuilding.class);
        util.exportExcel(response, list, "城市大厦信息数据");
    }

    /**
     * 获取城市大厦信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(lifeCityBuildingService.selectLifeCityBuildingById(id));
    }

    /**
     * 新增城市大厦信息
     */
    @Log(title = "城市大厦信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeCityBuilding lifeCityBuilding) {
        return toAjax(lifeCityBuildingService.insertLifeCityBuilding(lifeCityBuilding));
    }

    /**
     * 修改城市大厦信息
     */
    @Log(title = "城市大厦信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeCityBuilding lifeCityBuilding) {
        return toAjax(lifeCityBuildingService.updateLifeCityBuilding(lifeCityBuilding));
    }

    /**
     * 删除城市大厦信息
     */
    @Log(title = "城市大厦信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(lifeCityBuildingService.deleteLifeCityBuildingByIds(ids));
    }

    /**
     * 查询大厦排班信息
     */
    @PostMapping("/workclass")
    public AjaxResult viewWorkClass(@RequestBody LifeCityBuilding lifeCityBuilding) {
        return lifeCityBuildingService.viewWorkClass(lifeCityBuilding);
    }
}
